package net.xujialiang.XTestRPA.Controller.App;


import net.xujialiang.XTestRPA.Config.SpringSecurityConfig.SecurityUser;
import net.xujialiang.XTestRPA.Entity.App.AppVersion;
import net.xujialiang.XTestRPA.Model.ResultData;
import net.xujialiang.XTestRPA.Service.App.AppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static net.xujialiang.XTestRPA.Enum.ReturnCode.RC999;

@RequestMapping("/anonymous/api/app")
@RestController
public class AppversionController {

    @Autowired
    AppService appService;

    @RequestMapping(value = "/version", method = RequestMethod.POST)
    @ResponseBody
    public ResultData<AppVersion> fetch(@RequestBody Map<String, Object> reqBody, HttpServletRequest request, Authentication auth) {
        String platform = (String) reqBody.get("platform");
        try {
            AppVersion ret = appService.fetch(platform);
            return ResultData.success(ret);
        } catch (Exception e) {
            return ResultData.fail(RC999.getCode(), e.getMessage());
        }
    }
}
